package com.sq.universe.flowable.controller;

import com.sq.universe.base.controller.BaseController;
import com.sq.universe.base.entity.RespEntity;
import com.sq.universe.flowable.dao.WorkflowDao;
import com.sq.universe.flowable.entity.WorkflowEntity;
import com.sq.universe.flowable.service.WorkflowService;
import com.sq.universe.system.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/workflow")
public class WorkflowController extends BaseController {

    @Autowired
    private WorkflowService workflowService;

    @Autowired
    private WorkflowDao workflowDao;


    @GetMapping("/test")
    public RespEntity test(WorkflowEntity workflowEntity){
        return new RespEntity("查询成功",workflowDao.mapperTest());
    }



    @PostMapping("/queryTodo")
    public RespEntity queryTodo(WorkflowEntity workflowEntity){
        return new RespEntity("查询成功",workflowService.queryTodo(this.getCurrentUser(),workflowEntity));
    }

    @PostMapping("/queryDone")
    public RespEntity queryDone(WorkflowEntity workflowEntity){
        return new RespEntity("查询成功",workflowService.queryDone(this.getCurrentUser(),workflowEntity));
    }

    @PostMapping("/start")
    public RespEntity start(WorkflowEntity workflowEntity){
        workflowService.start( workflowEntity, this.getCurrentUser());
        return new RespEntity("启动成功" );
    }

    @PostMapping("/completeTask")
    public RespEntity completeTask(WorkflowEntity workflowEntity){
        workflowService.completeTask( workflowEntity, this.getCurrentUser());
        return new RespEntity("任务完成" );
    }

    @PostMapping("/rollback")
    public RespEntity rollback(WorkflowEntity workflowEntity){
        workflowService.rollback( workflowEntity,this.getCurrentUser());
        return new RespEntity("退货");
    }

    @PostMapping("/getForm")
    public RespEntity getForm(String formkey){
        return new RespEntity("查询成功", workflowService.getForm(formkey) );
    }

    @PostMapping("/history")
    public RespEntity history(WorkflowEntity workflowEntity){
        return new RespEntity("查询成功", workflowService.history(workflowEntity) );
    }

}
